package eerbaar.v2.app.strategy;

import eerbaar.client.ctr.IGameController;
import eerbaar.client.ctr.IGameControllerFactory;
import eerbaar.game.IGame;
import eerbaar.persona.IPersona;
import eerbaar.shared.service.ServiceFactory;
import eerbaar.v2.app.mover.IPersonaMover;

public class ProgramStrategy implements IPersonaStrategy {

    private final IPersona subject;

    private final String program;

    public ProgramStrategy(IPersona subject, String program) {
        this.subject = subject;
        this.program = program;
    }

    @Override
    public boolean move(IPersonaMover mover, IGame game) {

        boolean finished = true;

        if (this.program != null) {
            IGameControllerFactory factory = ServiceFactory
                    .getService(IGameControllerFactory.class);
            IGameController controller = factory.create(this.subject, game);

            finished = controller.input(this.program);
        }

        return !finished;
    }
}
